package com.zzyl.controller.customer;

import com.github.pagehelper.PageInfo;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.CustomerReservationDto;
import com.zzyl.dto.CustomerReservationPageParamDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.CustomerReservationVo;
import com.zzyl.vo.ReservationTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信小程序客户端 --- 预约管理接口
 */

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Long> getCancelledReservationCount() {
        log.info("查询取消预约次数");
        Long userId = UserThreadLocal.getUserId();
        log.info("用户：{}",userId);
        Long count = customerReservationService.getCancellCount(userId);
        log.info("用户{}，取消预约次数为：{}",userId,count);
        return success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation(value = "查询时间段剩余预约次数")
    public ResponseResult<List<ReservationTimeVo>> getCountByTime(Long time) {
        log.info("查询时间段剩余预约次数：{}",time);
        List<ReservationTimeVo> result = customerReservationService.getTimeCount(time);
        return success(result);
    }

    @PostMapping
    @ApiOperation(value = "新增预约")
    public ResponseResult addReservation(@RequestBody CustomerReservationDto customerReservationDto) {
        log.info("新增预约：{}",customerReservationDto);
        Long userId = UserThreadLocal.getUserId();
        customerReservationService.add(customerReservationDto,userId);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询预约")
    public ResponseResult<PageResponse<CustomerReservationVo>> getByPage(Integer pageNum,Integer pageSize,Integer status){
        log.info("预约信息分页查询：{}");
        Long userId = UserThreadLocal.getUserId();
        PageResponse<CustomerReservationVo> result = customerReservationService.getPage(pageNum, pageSize, status,userId);
        return success(result);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public ResponseResult cancelReservation(@PathVariable Long id){
        log.info("取消预约：{}",id);
        customerReservationService.changeStatusCancel(id);
        return success();
    }



}